package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.Update;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.FoodManagement;
import com.neuedu.yyzx.service.IFoodManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dya
 * @since 2021-04-27
 */
@RestController
@RequestMapping("//foodManagement")
public class FoodManagementController {

    @Autowired
    IFoodManagementService foodManagementService;
    @RequestMapping("/list")
    CommonResult list (Page page, FoodManagement foodManagement){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        if(foodManagement!= null && StringUtils.isNotEmpty(foodManagement.getCustomerName())){
            queryWrapper.like("customer_name",foodManagement.getCustomerName());

        }
        return CommonResult.success(foodManagementService.page(page,queryWrapper));

    }

    @RequestMapping("/add")
    CommonResult add(FoodManagement foodManagement){
        return CommonResult.success(foodManagementService.saveOrUpdate(foodManagement));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer id){
        return CommonResult.success(foodManagementService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult del(Integer id){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("id",id);
        return CommonResult.success(foodManagementService.update(updateWrapper));
    }

}
